package com.datamation.swadeshi.view;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.Selection;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import com.datamation.swadeshi.R;
import com.datamation.swadeshi.adapter.SetTitleAdapter;
import com.datamation.swadeshi.control.GPSTracker;
import com.datamation.swadeshi.control.ReferenceNum;
import com.datamation.swadeshi.control.SalesPrintPreviewAlertBox;
import com.datamation.swadeshi.control.Toast;
import com.datamation.swadeshi.control.data.DebtorDS;
import com.datamation.swadeshi.control.data.OrdDetDS;
import com.datamation.swadeshi.control.data.OrdHedDS;
import com.datamation.swadeshi.control.data.SalRepDS;
import com.datamation.swadeshi.model.OrdDet;
import com.datamation.swadeshi.model.OrdHed;

public class FragmentSalesManagementSummary extends Fragment{

	View view;
	EditText etHeaderDisVal, etHeaderDisPer,etGrossVal,etTotalReturn,etHeaderDis,etLineDis,etTotalDis,etTotalInvVal;
	
	Spinner paymentType;
	
	double sTotalGrossVal=0.00, sHeaderDisPer=0.00, sHeaderDisVal=0.00, sTotHeaderDiscount=0.00;
	
	//Shared Preferences variables 
	public static final String SETTINGS = "SETTINGS";
	public static SharedPreferences localSP;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		
		view = inflater.inflate(R.layout.sales_management_pre_sales_summary, container, false);
		
		localSP = getActivity().getSharedPreferences(SETTINGS,Context.MODE_WORLD_READABLE+Context.MODE_WORLD_WRITEABLE);
		
		setHasOptionsMenu(true);
		
		SetTitleAdapter adapter =new SetTitleAdapter();
		adapter.createCutomActionBarTitle("Summary", getActivity());
		
		etHeaderDisPer = (EditText) view.findViewById(R.id.et_cus_dis);
		etHeaderDisVal=(EditText) view.findViewById(R.id.et_invoice_dis);
		
		etGrossVal=(EditText) view.findViewById(R.id.et_gross_val);
		etTotalReturn=(EditText) view.findViewById(R.id.et_total_mr);		
		etHeaderDis=(EditText) view.findViewById(R.id.et_header_dis);
		etLineDis=(EditText) view.findViewById(R.id.et_line_dis);
		etTotalDis=(EditText) view.findViewById(R.id.et_total_dis);
		etTotalInvVal=(EditText) view.findViewById(R.id.et_total_invoice_val);
		
		paymentType=(Spinner) view.findViewById(R.id.spinner1);
		setPaymentType();
		
		
		
		//set current summary 
		setCurrentSummary();
		
		//cases
		etHeaderDisPer.addTextChangedListener(new TextWatcher(){
		    public void afterTextChanged(Editable s) {
		       
		    	headerDisPer();

		    }
		   	public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		}); 
		
		
		etHeaderDisVal.addTextChangedListener(new TextWatcher(){
		    public void afterTextChanged(Editable s) {
		       
		    	headerDisValue();

		    }
		    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
		    public void onTextChanged(CharSequence s, int start, int before, int count){}
		}); 
		
		return view;
		
	}
	
	private void headerDisPer() {
		// TODO Auto-generated method stub
		if(!(etGrossVal.equals("0.00"))){
			
			if(!(etHeaderDisPer.length() == 0)){
				
				if(!(etHeaderDisPer.equals("0.00"))){
					
					if(etHeaderDisPer.getText().toString().equals(".")){
	   					
						etHeaderDisPer.setText("0.");
	   					//Set cursor position to end of the text after updating the text of EditText 
	   					int position = etHeaderDisPer.length();
	   					Editable etext = etHeaderDisPer.getText();
	   					Selection.setSelection(etext, position);
					
					}
					
					sTotalGrossVal = Double.parseDouble(etGrossVal.getText().toString().replaceAll(",", "")) - 
								 (Double.parseDouble(etTotalReturn.getText().toString().replaceAll(",", "")) + Double.parseDouble(etLineDis.getText().toString().replaceAll(",", "")));
					
					if((etHeaderDisPer.length() == 0))
						sHeaderDisPer = 0.00;
					else
						sHeaderDisPer = sTotalGrossVal * Double.parseDouble(etHeaderDisPer.getText().toString())/100.00;
					
					if((etHeaderDisVal.length() == 0))
						sHeaderDisVal = 0.00;
					else
						sHeaderDisVal = Double.parseDouble(etHeaderDisVal.getText().toString());
					
					sTotHeaderDiscount = sHeaderDisPer + sHeaderDisVal;
					
					etHeaderDis.setText(String.format("%,.2f",sTotHeaderDiscount));
					
					if(sTotalGrossVal <= sTotHeaderDiscount){
						etHeaderDis.setText("0.00");
						etHeaderDisPer.setText("0.00");
						etHeaderDisVal.setText("0");
						
						sTotalGrossVal=0.00;
						sTotHeaderDiscount=0.00;
						
						Toast toast=new Toast();
						toast.createToastErrorMessage("Maximum Discount Amount Exceed...", getActivity());
					}
					
					setCurrentSummary(); 
				}
			}else{
				if(!(etHeaderDisPer.equals("0.00"))){
					
					if(etHeaderDisPer.getText().toString().equals(".")){
	   					
						etHeaderDisPer.setText("0.");
	   					//Set cursor position to end of the text after updating the text of EditText 
	   					int position = etHeaderDisPer.length();
	   					Editable etext = etHeaderDisPer.getText();
	   					Selection.setSelection(etext, position);
					
					}
					
					sTotalGrossVal = Double.parseDouble(etGrossVal.getText().toString().replaceAll(",", "")) - 
								 (Double.parseDouble(etTotalReturn.getText().toString().replaceAll(",", "")) + Double.parseDouble(etLineDis.getText().toString().replaceAll(",", "")));
					
								
					if((etHeaderDisPer.length() == 0))
						sHeaderDisPer = 0.00;
					else
						sHeaderDisPer = sTotalGrossVal * Double.parseDouble(etHeaderDisPer.getText().toString())/100.00;
					
					Log.v("sHeader Dis Per", sHeaderDisPer+"");
					
						if((etHeaderDisVal.length() == 0))
							sHeaderDisVal = 0.00;
						else
							sHeaderDisVal = Double.parseDouble(etHeaderDisVal.getText().toString());
					
					sTotHeaderDiscount = sHeaderDisPer + sHeaderDisVal;
					
					etHeaderDis.setText(String.format("%,.2f",sTotHeaderDiscount));
					
					
					
					if(sTotalGrossVal <= sTotHeaderDiscount){
						
						etHeaderDis.setText("0.00");
						etHeaderDisPer.setText("0.00");
						etHeaderDisVal.setText("0");
						
						sTotalGrossVal=0.00;
						sTotHeaderDiscount=0.00;
						
						Toast toast=new Toast();
						toast.createToastErrorMessage("Maximum Discount Amount Exceed...", getActivity());
					}
					
					setCurrentSummary(); 
				}	
			}
		}   
		

	}
	
	private void headerDisValue() {
		// TODO Auto-generated method stub
		if(!(etGrossVal.equals("0.00"))){
			
			if(!(etHeaderDisVal.length() == 0)){
				
				if(!(etHeaderDisVal.equals("0.00"))){
					
					sTotalGrossVal = Double.parseDouble(etGrossVal.getText().toString().replaceAll(",", "")) - 
								 (Double.parseDouble(etTotalReturn.getText().toString().replaceAll(",", "")) + Double.parseDouble(etLineDis.getText().toString().replaceAll(",", "")));
					
					if((etHeaderDisPer.length() == 0))
						sHeaderDisPer = 0.00;
					else
						sHeaderDisPer = sTotalGrossVal * Double.parseDouble(etHeaderDisPer.getText().toString())/100.00;
					
					sHeaderDisVal = Double.parseDouble(etHeaderDisVal.getText().toString());
					
					sTotHeaderDiscount = sHeaderDisPer + sHeaderDisVal;
					
					etHeaderDis.setText(String.format("%,.2f",sTotHeaderDiscount));
					
					if(sTotalGrossVal <= sTotHeaderDiscount){
						etHeaderDis.setText("0.00");
						etHeaderDisPer.setText("0.00");
						etHeaderDisVal.setText("0");
						
						sTotalGrossVal=0.00;
						sTotHeaderDiscount=0.00;
						
						Toast toast=new Toast();
						toast.createToastErrorMessage("Maximum Discount Amount Exceed...", getActivity());
					}
					
					setCurrentSummary(); 
				}
			}else{
				if(!(etHeaderDisVal.equals("0.00"))){
					
										
					sTotalGrossVal = Double.parseDouble(etGrossVal.getText().toString().replaceAll(",", "")) - 
								 (Double.parseDouble(etTotalReturn.getText().toString().replaceAll(",", "")) + Double.parseDouble(etLineDis.getText().toString().replaceAll(",", "")));
					
					if((etHeaderDisPer.length() == 0))
							sHeaderDisPer = 0.00;
					else
						sHeaderDisPer = sTotalGrossVal * Double.parseDouble(etHeaderDisPer.getText().toString())/100.00;
					
					Log.v("sHeader Dis Per", sHeaderDisPer+"");
					
					
					if((etHeaderDisVal.length() == 0))
						sHeaderDisVal = 0.00;
					else
						sHeaderDisVal = Double.parseDouble(etHeaderDisVal.getText().toString());
					
					sTotHeaderDiscount = sHeaderDisPer + sHeaderDisVal;
					
					etHeaderDis.setText(String.format("%,.2f",sTotHeaderDiscount));
					
					
					
					if(sTotalGrossVal <= sTotHeaderDiscount){
						
						etHeaderDis.setText("0.00");
						etHeaderDisPer.setText("0.00");
						etHeaderDisVal.setText("0");
						
						sTotalGrossVal=0.00;
						sTotHeaderDiscount=0.00;
						
						Toast toast=new Toast();
						toast.createToastErrorMessage("Maximum Discount Amount Exceed...", getActivity());
					}
					
					setCurrentSummary(); 
				}	
			}
		}  
	}
	
	private void setCurrentSummary() {

			MainActivity activity = (MainActivity) getActivity();
			OrdDetDS ordDetDS=new OrdDetDS(activity);
			ReferenceNum referenceNum =new  ReferenceNum(getActivity());
			OrdHedDS hedDS =new OrdHedDS(getActivity());
			
			ArrayList<OrdHed> getOrdHed = hedDS.getAllActiveOrdHed(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal)));
			
			if(getOrdHed.isEmpty()){
				
				Toast toast=new Toast();
				toast.createToastMessage("You must enter at least one sales item", activity);
				getActivity().getActionBar().setSelectedNavigationItem(1);
				
			}
			
			
			

			etGrossVal.setText(String.format("%,.2f",Double.parseDouble(ordDetDS.getGrossValue(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))))));
			
			etLineDis.setText(String.format("%,.2f",Double.parseDouble(ordDetDS.getTotalLineDiscount(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))))));
			
			etTotalReturn.setText(String.format("%,.2f",Double.parseDouble(ordDetDS.getTotalReturns(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))))));
						
			Double totDiscount=Double.parseDouble(etHeaderDis.getText().toString().replaceAll(",", "")) + Double.parseDouble(ordDetDS.getTotalLineDiscount(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))));
			etTotalDis.setText(String.format("%,.2f",totDiscount));
			
			Double totalInvoiceVal=Double.parseDouble(ordDetDS.getGrossValue(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))))-(Double.parseDouble(ordDetDS.getTotalReturns(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))))+totDiscount);
			etTotalInvVal.setText(String.format("%,.2f",totalInvoiceVal));
			
			
			//If gross amount is Zero then disable header discount
			if(Double.parseDouble(etGrossVal.getText().toString().replaceAll(",", "")) == 0.00) {
				
				etHeaderDisVal.setEnabled(false);
				etHeaderDisPer.setEnabled(false);
				
				etHeaderDisVal.setTextColor(Color.parseColor("#CACACA"));
				etHeaderDisPer.setTextColor(Color.parseColor("#CACACA"));
							
			}else{
		
				etHeaderDisVal.setEnabled(true);
				etHeaderDisPer.setEnabled(true);
				
				etHeaderDisVal.setTextColor(Color.parseColor("#000000"));
				etHeaderDisPer.setTextColor(Color.parseColor("#000000"));
				
			}
		
	}



	private void setPaymentType() {
		// TODO Auto-generated method stub
		List<String> list = new ArrayList<String>();
		list.add("Cash");
		list.add("Bill to Bill");
		list.add("Cheque");
		
		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item, list);
		dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		paymentType.setAdapter(dataAdapter);

	}
	
	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		
		for(int i = 0; i < menu.size(); ++i){
			menu.removeItem(menu.getItem(i).getItemId());
		}
		
		inflater.inflate(R.menu.frag_per_sales_summary, menu);
		//getActivity().getActionBar().setTitle("Invoice List");
		//getActivity().getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#288dab")));
		super.onCreateOptionsMenu(menu, inflater);
	}
	
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == R.id.action_pre_sales_save){
			
			if(Double.parseDouble(etGrossVal.getText().toString().replaceAll(",", "")) != 0.00){
				setBluetooth(true);
				saveSummaryDialog(getActivity());
			}
				
		}
		
		if(item.getItemId() == R.id.action_pre_sale_undo){
			
			undoEditingData(getActivity());
						
		}
		return super.onOptionsItemSelected(item);
	}
	
	private String currentTime(){
		Calendar cal = Calendar.getInstance();
    	cal.getTime();
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
    	return sdf.format(cal.getTime());
	}
	
	private String currentDate() {
		// TODO Auto-generated method stub
		//current date and time 
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		return dateFormat.format(date);
		
	}

	private void undoEditingData(final Context context){

		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
		//alertDialogBuilder.setTitle(title);
		alertDialogBuilder.setMessage("Are you sure you want to Undo this entry?");
		final OrdHedDS ordHedDS =new OrdHedDS(getActivity());
		final OrdDetDS detDS=new OrdDetDS(getActivity());
		alertDialogBuilder.setIcon(android.R.drawable.ic_dialog_alert);
		alertDialogBuilder
				.setCancelable(false)
				.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								
								ReferenceNum referenceNum =new  ReferenceNum(getActivity());
								MainActivity activity =(MainActivity) getActivity(); 
								
								//delete data
								try {
									ordHedDS.restData(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))); //FORDHED DATA
								}catch(Exception e){
									Log.w("Reset FORDHED Data Erorrrr ", e.toString());
								}
								try {
									detDS.restData(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal))); // FORDDET DATA
								}catch(Exception e){
									Log.w("Reset FORDDET Data Erorrrr ", e.toString());
								}
								
								activity.cusPosition=0;
								activity.selectedDebtor=null;
								activity.selectedOrdHed=null;
								
								Toast toast=new Toast();
								toast.createToastMessage("Undo Success", getActivity());
								getActivity().getActionBar().setSelectedNavigationItem(0);
							}
					})
				.setNegativeButton("No",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,	int id) {
								
								dialog.cancel();
								
								
							}
						});
		
		AlertDialog alertD = alertDialogBuilder.create();

		alertD.show();
	}
	
	private void saveSummaryDialog(final Context context){
		
		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
		//alertDialogBuilder.setTitle(title);
		alertDialogBuilder.setMessage("Are you sure you want to save this entry?");
		alertDialogBuilder.setIcon(android.R.drawable.ic_dialog_alert);
		alertDialogBuilder
				.setCancelable(false)
				.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
							
							
									
									OrdHed hed =new OrdHed();
									OrdHedDS ordHedDS =new OrdHedDS(getActivity());
									OrdDetDS detDS=new OrdDetDS(getActivity());
									ArrayList<OrdHed> ordHedList=new ArrayList<OrdHed>();
									GPSTracker gpsTracker=new GPSTracker(getActivity());
									ReferenceNum referenceNum =new  ReferenceNum(getActivity());
									SalRepDS repDS=new SalRepDS(getActivity());
									
									
									ArrayList<OrdHed> getOrdHed = ordHedDS.getAllActiveOrdHed(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal)));
									
									if(!getOrdHed.isEmpty()){
										
										for (OrdHed ordHed : getOrdHed) {
												//hed=ordHed;
											hed.setFORDHED_REFNO(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal)));
											hed.setFORDHED_DEB_CODE(ordHed.getFORDHED_DEB_CODE());
											hed.setFORDHED_ADD_DATE(ordHed.getFORDHED_ADD_DATE());
											hed.setFORDHED_DELV_DATE(ordHed.getFORDHED_DELV_DATE());
											hed.setFORDHED_ROUTE_CODE(ordHed.getFORDHED_ROUTE_CODE());
											hed.setFORDHED_MANU_REF(ordHed.getFORDHED_MANU_REF());
											hed.setFORDHED_REMARKS(ordHed.getFORDHED_REMARKS());
											hed.setFORDHED_ADD_MACH(ordHed.getFORDHED_ADD_MACH());
											hed.setFORDHED_ADD_USER(ordHed.getFORDHED_ADD_USER());
											hed.setFORDHED_APP_DATE(ordHed.getFORDHED_APP_DATE());
											hed.setFORDHED_APPSTS(ordHed.getFORDHED_APPSTS());
											hed.setFORDHED_APP_USER(ordHed.getFORDHED_APP_USER());
											hed.setFORDHED_CUR_CODE(ordHed.getFORDHED_CUR_CODE());
											hed.setFORDHED_CUR_RATE(ordHed.getFORDHED_CUR_RATE());
											hed.setFORDHED_LOC_CODE(ordHed.getFORDHED_LOC_CODE());
											
											}
									}
									
									hed.setFORDHED_REFNO(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal)));
									hed.setFORDHED_BP_TOTAL_DIS(etTotalDis.getText().toString());
									hed.setFORDHED_B_TOTAL_AMT(etTotalInvVal.getText().toString());
									hed.setFORDHED_B_TOTAL_DIS(etTotalDis.getText().toString());
									hed.setFORDHED_B_TOTAL_TAX("0.00");
									hed.setFORDHED_DIS_PER(etHeaderDisPer.getText().toString());
									hed.setFORDHED_END_TIME_SO(currentTime());
									hed.setFORDHED_START_TIME_SO(localSP.getString("SO_Start_Time", "").toString());
									hed.setFORDHED_LATITUDE(gpsTracker.getLatitude()+"");
									hed.setFORDHED_LONGITUDE(gpsTracker.getLongitude()+"");
									hed.setFORDHED_ADDRESS(localSP.getString("GPS_Address", "").toString());
									hed.setFORDHED_COST_CODE("000");
									hed.setFORDHED_RECORD_ID("");
									hed.setFORDHED_TAX_REG("");
									hed.setFORDHED_TOTAL_TAX("0.00");
									hed.setFORDHED_TOTALDIS(etHeaderDisVal.getText().toString());
									hed.setFORDHED_TOTAL_ITM_DIS(etLineDis.getText().toString());
									hed.setFORDHED_TOT_MKR_AMT(etTotalReturn.getText().toString());
									hed.setFORDHED_TIMESTAMP_COLUMN("");
									hed.setFORDHED_TOTAL_AMT(etTotalInvVal.getText().toString());
									hed.setFORDHED_TXN_DATE(currentDate());
									hed.setFORDHED_TXN_TYPE("21");
									hed.setFORDHED_REPCODE(repDS.getCurrentRepCode());
									hed.setFORDHED_IS_ACTIVE("1");
									hed.setFORDHED_HED_DIS_VAL(sHeaderDisVal+"");
									hed.setFORDHED_HED_DIS_PER_VAL(String.format("%,.2f",sHeaderDisPer)+"");//String.format("%,.2f",sHeaderDisPer)
									
									hed.setFORDHED_PAYMENT_TYPE(paymentType.getSelectedItem().toString());
									
									ordHedList.add(hed);
									
									if(ordHedDS.createOrUpdateOrdHed(ordHedList)>0){
										
										//update status
										ordHedDS.InactiveStatusUpdate(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal)));
										detDS.InactiveStatusUpdate(referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal)));
										
										MainActivity activity =(MainActivity) getActivity(); 
										
										activity.cusPosition=0;
										activity.selectedDebtor=null;
										activity.selectedOrdHed=null;

										SalesPrintPreviewAlertBox alertBox=new SalesPrintPreviewAlertBox(getActivity());
										alertBox.PrintDetailsDialogbox(getActivity(), "",referenceNum.getCurrentRefNo(getResources().getString(R.string.NumVal)));
										
										//next refno
										referenceNum.nNumValueInsertOrUpdate(getResources().getString(R.string.NumVal));
										
										getActivity().getActionBar().setSelectedNavigationItem(0);
										
										// resetting values for a new invoice
										activity.getActionBar().removeAllTabs();
										// setting navigation mode to standard
										activity.getActionBar().setNavigationMode(0);

										Toast toast=new Toast();
										toast.createToastMessage("Invoice saved to database.", getActivity());
									
										//toast.createToastErrorMessage("Print Report..", getActivity());
										
										
										getActivity().getFragmentManager().popBackStack();
										
										dialog.dismiss();
										
										
									}else{
										Toast toast=new Toast();
										toast.createToastErrorMessage("Faild", getActivity());
									}
								}
						})
				.setNegativeButton("No",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,	int id) {
						    	dialog.cancel();
							}
						});
		
		AlertDialog alertD = alertDialogBuilder.create();

		alertD.show();
	}
	
	
	private void clearTextfields(){
		
		etHeaderDisPer.setText("0.00");
		etHeaderDisVal.setText("0.00");
		etGrossVal.setText("0.00");
		etTotalReturn.setText("0.00");
		etHeaderDis.setText("0.00");
		etLineDis.setText("0.00");
		etTotalDis.setText("0.00");
		etTotalInvVal.setText("0.00");
		
		setPaymentType();
		
		
	}
	

		
		public static boolean setBluetooth(boolean enable) {
		    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
		    boolean isEnabled = bluetoothAdapter.isEnabled();
		    if (enable && !isEnabled) {
		        return bluetoothAdapter.enable(); 
		    }
		    else if(!enable && isEnabled) {
		        return bluetoothAdapter.disable();
		    }
		    // No need to change bluetooth state
		    return true;
		}

}
